The if-null
operator ??
allows providing a default value when dealing with null
. It only coalesces when the
original value is null
. Therefore, it is safer and shorter than relying upon testing against null
or undefined
explicitly.
This rule reports when conditionals (?
) can be safely replaced with coalescing (??
).